package com.ihelp.controller;

import com.ihelp.entities.CommonResult;
import com.ihelp.pojo.Order;
import com.ihelp.pojo.OrderStatus;
import com.ihelp.service.OrderService;
import com.ihelp.service.OrderStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiuZiMing
 * @since 2023-05-23
 */
@RestController
@Slf4j
@RequestMapping("/orderStatus")
public class OrderStatusController {
    @Autowired
    private OrderStatusService orderStatusService;
    @GetMapping("/all")
    public CommonResult getAllOrderStatus() {
        List<OrderStatus> allOrderStatus = orderStatusService.getAllOrderStatus();
        return new CommonResult(200, "获取所有订单状态成功", allOrderStatus);
    }

    @GetMapping("/id/{id}")
    public CommonResult getOrderStatusById(@PathVariable Integer id){
        OrderStatus orderStatusById = orderStatusService.getOrderStatusById(id);
        if(orderStatusById!=null){
            return new CommonResult<>(200,"根据id:"+id+",获取订单状态成功",orderStatusById);
        }else {
            return new CommonResult<>(204,"根据id:"+id+",未找到订单状态");
        }
    }
}
